package com.springboot.orderno.controller;

import com.springboot.orderno.common.ResultVO;
import com.springboot.orderno.service.OrderNoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orderNo/")
@CrossOrigin(origins = "*",maxAge = 3600)
public class OrderNoController {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private OrderNoService orderNoService;

    /**
     * 插入示例
     * orderNoPrefix: HDD
     * 生成示例：HDD2101180935590001
     *
     * @param source        数据来源
     * @param orderNoPrefix 订单编号前缀
     * @param orderNoType       订单类型
     * @return
     */
    @PostMapping("insert")
    public ResultVO<String> getOrderNo(@RequestParam Integer source, @RequestParam String orderNoPrefix,
                                       @RequestParam String orderNoType,@RequestParam Integer orderNoLength) {
        return orderNoService.insert(source, orderNoPrefix, orderNoType,orderNoLength);
    }

    /**
     * 订单号生成示例
     *
     * @return
     */
    @GetMapping("getOrderNO")
    public ResultVO<String> getOrderNO() {
        return orderNoService.getOrderNO("HDD", "PO",6);
    }

}
